/**
 * Created by zhijie on 2016/12/15.
 */
/**
 * Created by hezhijie on 2016/11/22.
 */
var agentDetailModule = angular.module("agentDetail", []);
agentDetailModule.controller("agentDetailCtrl", ['$scope',
    function ($scope) {
        $scope.init = function () {
            $scope.getAgent();
        }

        $scope.getAgent = function () {
            if ($scope.$stateParams.id) {
                $post(basePath + "/rest/agent/_get", {id: $scope.$stateParams.id}, function (result) {
                    $scope.agent = result.resultValue;
                    $scope.$apply();
                })
            }
        }

        $scope.saveAgentDetail = function () {
            if ($scope.agent.id) {
                $post(basePath + "/rest/agent/_update", $scope.agent, function (result) {
                    $scope.$state.go("home.content.agent.agentList")
                })
            } else {
                $post(basePath + "/rest/agent/_add", $scope.agent, function (result) {
                    $scope.$state.go("home.content.agent.agentList")
                })
            }
        }

        $scope.init();
    }
]);
